home *** CD-ROM | disk | FTP | other *** search
- /* fclose.c */
- #include <stdio.h>
- char file2[80], /* Name of file to open */
- line[81]; /* or lines from the file */
- FILE *inputfile; /* File pointer to opened file */
- main()
- {
- printf ("Enter name of file to open: ");
- gets(file2);
- /* Open the file */
- if ((inputfile = fopen(file2, "r")) == NULL)
- {
- printf ("Error opening file: %s\n", file2);
- exit(0);
- }
- printf("==== Contents of input file ====\n");
- while (fgets(line, 80, inputfile) != NULL)
- {
- printf(line);
- }
- /* Now close the file and exit */
- fclose(inputfile);
- }